﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
using DTO;
namespace DAO
{
    public class DAOMonHoc:DataProvider
    {
        public static DataTable LayDSMonHoc()
        {
            DataTable BangDS;
            OleDbConnection ketNoi = null;
            ketNoi = Connect();
            string chuoilenh ="select * from MonHoc";
            DataSet ds = new DataSet();
            OleDbDataAdapter da = new OleDbDataAdapter(chuoilenh, ketNoi);
            da.Fill(ds);
            BangDS = ds.Tables[0];
            Disconnect();
            return BangDS;
        }
        public static DataTable LayDSMonHoc(string hocky)
        {
            DataTable BangDS;
            OleDbConnection ketNoi = null;
            ketNoi = Connect();
            string chuoilenh = "select * from MonHoc where hocky=@hocky";
            DataSet ds = new DataSet();
            OleDbDataAdapter da = new OleDbDataAdapter(chuoilenh, ketNoi);
            da.SelectCommand.Parameters.AddWithValue("@hocky", hocky);
            da.Fill(ds);
            BangDS = ds.Tables[0];
            Disconnect();
            return BangDS;
        }
        public static int ThemMonHoc(DTOMonHoc mon)
        {            
            OleDbConnection ketNoi = Connect();
            string chuoilenh = "insert into MonHoc(MaMonHoc,TenMonHoc,HocKy) values(@MaMH,@TenMH,@HocKy)";
            OleDbCommand lenh = new OleDbCommand(chuoilenh, ketNoi);
            OleDbParameter values = new OleDbParameter("@MaMH",mon.MaMH);
            lenh.Parameters.Add(values);
            values = new OleDbParameter("@TenMH",mon.TenMH);
            lenh.Parameters.Add(values);
            values = new OleDbParameter("@HocKy", mon.HocKy);
            lenh.Parameters.Add(values);
            int result = lenh.ExecuteNonQuery();
            Disconnect();
            return result;           
        }
        public static int XoaMonHoc(string MaMH)
        {
            OleDbConnection ketNoi = Connect();
            string chuoilenh = "delete from MonHoc where MaMonHoc=@MaMH";
            OleDbCommand lenh = new OleDbCommand(chuoilenh, ketNoi);
            OleDbParameter values = new OleDbParameter("@MaMH", MaMH);
            lenh.Parameters.Add(values);
            int result = lenh.ExecuteNonQuery();
            Disconnect();
            return result;
        }
        public static int SuaMonHoc(DTOMonHoc mon, string MaMHCu)
        {
            OleDbConnection ketNoi = Connect();
            string chuoilenh = "update MonHoc set MaMonHoc=@MaMH, TenMonHoc=@TenMH, HocKy=@HocKy where MaMonHoc=@MaMHCu";
            OleDbCommand lenh = new OleDbCommand(chuoilenh, ketNoi);
            OleDbParameter values = new OleDbParameter("@MaMH", mon.MaMH);
            lenh.Parameters.Add(values);
            values = new OleDbParameter("@TenMH", mon.TenMH);
            lenh.Parameters.Add(values);
            values = new OleDbParameter("@HocKy", mon.HocKy);
            lenh.Parameters.Add(values);
            values = new OleDbParameter("@MaMHCu", MaMHCu);
            lenh.Parameters.Add(values);            
            int result = lenh.ExecuteNonQuery();
            Disconnect();
            return result;
        }
    }
}
